package com.studyinghome.controller;

import com.alibaba.fastjson2.JSON;
import com.studyinghome.entity.Order;
import com.studyinghome.entity.OrderItem;
import com.studyinghome.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Leslie
 * @create 2023-02-10 14:52
 **/
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/query/{orderNo}")
    public String query(@PathVariable String orderNo) {
        Order order = orderService.queryByOrderNo(orderNo);
        return JSON.toJSONString(order);
    }

    @GetMapping("/detail/{itemId}")
    public String queryItem(@PathVariable Long itemId) {
        OrderItem item = orderService.queryItem(itemId);
        return JSON.toJSONString(item);
    }
}
